using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using Pervote.Core;
using Pervote.Core.Logic;

public partial class CategoryMain : RegularPageBase
{
    string fqCatName = "";

    private List<Poll> randomPolls;
    public List<Poll> RandomPolls
    {
        get { return randomPolls; }
        set { randomPolls = value; }
    }

    new protected void Page_Load(object sender, EventArgs e)
    {
        LoadRandomPolls();
        ShortPollView.LoadAny(randomPolls);
    }

    protected string GetCloudData()
    {
        Cloud cloud = new Cloud(randomPolls);
        return cloud.GetCloudView();
    }

    private void LoadRandomPolls()
    {
        fqCatName = "/";    //default
        string strCatName = Request.QueryString["name"];
        if (strCatName != null && strCatName != "")
        {
            fqCatName = strCatName;
            if (!fqCatName.EndsWith("/")) fqCatName += "/";
        }
        PollManager pollManager = new PollManager();
        ErrorInfo error = new ErrorInfo();
        randomPolls = pollManager.GetRandomPolls(fqCatName, 40, error);
    }

    protected string GetFQCategoryName()
    {
        return fqCatName;
    }

    protected string GetSimpleCategoryName()
    {
        if (fqCatName == "/") return "All Categories";
        string simpleName = fqCatName.Replace('/', '-');
        return simpleName.Trim('-');
    }
}
